/**
 * SendPanel mit Textfeld und Button
 * @author Matze
 */

package chat.client.gui;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextField;


@SuppressWarnings("serial")
public class SendPanel extends JPanel implements ActionListener {
	
	private JTextField sendField = new JTextField();
	private JButton sendButton = new JButton("Senden");
	private String clientName;
	
	/**
	 * Konstruktor
	 */
	public SendPanel(String clientName) {
		this.clientName = clientName;
		setLayout(new FlowLayout());
		sendField.setColumns(21);
		add(sendField);
		add(sendButton);
		sendField.addActionListener(this);
		sendButton.addActionListener(this);
		sendButton.setActionCommand("Senden");
		setVisible(true);
	}
	
	/**
	 * Action-Methode
	 */
	public void actionPerformed(ActionEvent e) {
		String text;
		
		text = sendField.getText();
		if(sendField.getText().equals(""))
			sendField.setText("");
		else {
			ClientTextPanel.print(clientName + ": " + text, ClientTextPanel.textField);
			sendField.setText("");
		}
	}
	
}
